package com.yz.newspaper.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yz.newspaper.pojo.po.User;
import com.yz.newspaper.mapper.UserMapper;
import com.yz.newspaper.pojo.unitPo.PageBean;
import com.yz.newspaper.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-04-21
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public User login(User user) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>();
        lambdaQueryWrapper
                .eq(User::getPhone, user.getPhone());
        return baseMapper.selectOne(lambdaQueryWrapper);
    }

    @Override
    public PageBean<User> getUserAll(String username, Integer pageNum, Integer pageSize) {
        Page<User> pages = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>().like(username != null && username != "", User::getUsername, username);
        Page<User> userPage = baseMapper.selectPage(pages, lambdaQueryWrapper);
        PageBean<User> userPageBean = new PageBean<>(userPage.getRecords(), userPage.getTotal());
        return userPageBean;
    }

}